<template>
  <main-wrap class="ptp1">
    <!-- <div class="weui-cells">
      <a class="weui-cell weui-cell_access fullL" href="javascript:;">
        <div class="partS">
            <p>维修项</p>
        </div>
        <router-link :to="'/mrolist'" class="weui-cell__ft black partB">{{mrotype}}</router-link>
      </a>

      <div class="weui-cell">
          <div class="weui-cell__hd"><label for="" class="weui-label">设备号</label></div>
          <div class="weui-cell__bd">
              <input class="weui-input aright" v-model="code" placeholder="请输入设备号">
          </div>
          <div class="weui-cell__ft mlp1" @click="scancode">
              <i class="iconfont icon-iconfontscanning"></i>
          </div>
      </div>
    </div> -->

    <div class="weui-cells__title">上报内容</div>
    <my-textarea @areatextchg="areatextchg" :pholder="'请在这里输入上报内容'"></my-textarea>

    <my-uploader ref="uploader"></my-uploader>

    <div class="weui-cells" v-show="false">
      <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">预计花费</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="number" pattern="[0-9]*" placeholder="请输入金额" v-model="money">
        </div>
      </div>
    </div>

    <div class="paddingP3 mtp4">
      <a href="javascript:;" class="weui-btn weui-btn_primary" :class="{'weui-btn_disabled': btnDisabled}" @click="gonext">确认</a>
    </div>
  </main-wrap>
</template>

<script>
import MainWrap from '@/components/mainWrap'
import MyTextarea from '@/components/mytextarea'
import MyUploader from '@/components/myuploader'
import { mapState, mapMutations } from 'vuex'

import wx from 'weixin-js-sdk'
export default {
  name: 'Communication',
  data () {
    return {
      ferror: false,
      mrotype: '',
      code: '',
      money: 0,
      descritext: '',
      btnDisabled: true
    }
  },
  components: {
    MainWrap,
    MyTextarea,
    MyUploader
  },
  computed: {
    ...mapState(['user_report_upload_items', 'order_detail', 'user_report_upload_items_new'])
  },
  watch: {
    code () {
      this.checkinput()
    },
    money () {
      this.checkinput()
    },
    descritext () {
      this.checkinput()
    },
    user_report_upload_items () {
      this.checkinput()
    }
  },
  activated () {
    this.code = ''
    this.money = 0
    this.descritext = ''
    this.$refs.uploader.cleardata()
    this.mrotype = '请选择维修项'
    this.empty_user_report_upload_items_new()

    this.checkinput()
  },
  mounted () {
    this.cm.overscroll(document.querySelector('.ptp1'))
    // this.wxInit()
    this.dataInit()
  },
  methods: {
    ...mapMutations(['empty_user_report_upload_items', 'empty_user_report_upload_items_new', 'add_user_report_upload_items_new', 'del_user_report_upload_items_new']),
    gonext () {
      if (!this.btnDisabled) {
        // this.$toast.loading({
        //   duration: 0,
        //   message: '请稍等...'
        // })

        let params = {
          attachment: JSON.stringify(this.user_report_upload_items_new),
          repairId: localStorage.oid,
          idea: this.descritext,
          agree: 'feidao'
        }
        console.log(JSON.stringify(params))
        this.cm.myajax('sys/userrepair/reportToForeman', params, (data) => {
        // this.cm.myajax('/sys/userrepair/endOrder', params, (data) => {
          this.$toast.clear()

          localStorage.ostat = '30'
          this.$router.push('/morderdetail/' + localStorage.oid)
        })
      }
    },
    checkinput () {
      // if (this.mrotype !== '请选择维修项' && this.code !== '' && this.money !== '' && this.descritext !== '' && this.user_report_upload_items.length > 0) {
      if (this.descritext !== '') {
        this.btnDisabled = false
      } else {
        this.btnDisabled = true
      }
    },
    areatextchg (text) {
      this.descritext = text
    },
    dataInit () {
      this.empty_user_report_upload_items_new()
      this.empty_user_report_upload_items()
    }
  },
  beforeRouteEnter (to, from, next) {
    localStorage.mroreportfrom = from.path
    next()
  }
}
</script>
